﻿'// ========================================================================= '
'// ------------------------------------------------------------------------- '
'//!				\file		CST_Grid.vb
'			        \date		june 2010
'			        \author		TNick
'
'			        \brief		Dialog for grid settings
'
'
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'   This file is considered universal knowledge. No restrictions
'   are imposed; use as you see fit.
'   Please read ReadMe.txt and Licence.txt in root folder
'   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'   
'
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
'//
'//
'//
'//
'//  IMPORTS     ------------------------------------------------------------ '
#Region "Imports"

Imports System.Windows.Forms

#End Region
'//  IMPORTS     ============================================================ '
'//
'//
'//
'//
'//  DEFINITIONS    --------------------------------------------------------- '




'//  DEFINITIONS    ========================================================= '
'//
'//
'//
'//
'//  DATA    ---------------------------------------------------------------- '


'//  DATA    ================================================================ '
'//
'//
'//
'//
'//  CLASS    --------------------------------------------------------------- '

Public Class CST_Grid
    '// --------------------------------------------------------------------- '
    '// Data
    Public Const MODE_SETTINGS As Integer = 0
    Public Const MODE_MODEL As Integer = 1
    Public Const MODE_PAPER As Integer = 2
    Private iMode As Integer
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Public Sub New(Optional iOpMode As Integer = MODE_SETTINGS )
        InitializeComponent()

        iMode = iOpMode

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub OK_Button_Click(ByVal sender As System.Object, _
                                ByVal e As System.EventArgs) _
                                Handles OK_Button.Click
        Dim lcStgs As CRJSTG
        Select Case iMode
            Case MODE_SETTINGS
                If (GetStgs(CM_Grid.Stgs,True,True)) Then
                    Me.DialogResult = System.Windows.Forms.DialogResult.OK
                    Me.Close()
                End If
            Case MODE_MODEL
                If (GetStgs(lcStgs,True,False)) Then
                    Me.Hide

                    CM_Grid.Do_Model_Grid(lcStgs)

                    Autodesk.AutoCAD.ApplicationServices. _
                    Application.ShowModelessDialog(Me)
                End If
            Case MODE_PAPER
                If (GetStgs(lcStgs,False,True)) Then
                    Me.Hide

                    CM_Grid.Do_Paper_Grid(lcStgs)

                    Autodesk.AutoCAD.ApplicationServices. _
                    Application.ShowModelessDialog(Me)
                End If
        End Select


    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) _
                                    Handles Cancel_Button.Click
        
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// 
    Private Sub CST_Grid_Load( _
        ByVal sender As System.Object,  _
        ByVal e As System.EventArgs) _
        Handles MyBase.Load

        Me.Text = CMain._T(tx.GRID) & ". " & _
            CMain._T(tx.SETTINGS) & ". "

        Me.TP_Model.Text = CMain._T(tx.MODEL)
        Me.TP_Paper.Text = CMain._T(tx.PAPER)

        Me.GRP_MBorder.Text = CMain._T(tx.BORDER)
        Me.GRP_PBorder.Text = CMain._T(tx.BORDER)
        Me.GRP_MInside.Text = CMain._T(tx.INSIDE)
        Me.GRP_PInside.Text = CMain._T(tx.INSIDE)

        Me.CK_MB_Marker.Text = CMain._T(tx.MARKER)
        Me.CK_PB_Marker.Text = CMain._T(tx.MARKER)
        Me.CK_MI_Marker.Text = CMain._T(tx.MARKER)
        Me.CK_PI_Marker.Text = CMain._T(tx.MARKER)

        Me.CK_MB_Text.Text = CMain._T(tx.VALUES)
        Me.CK_PB_Text.Text = CMain._T(tx.VALUES)
        Me.CK_MI_Text.Text = CMain._T(tx.VALUES)
        Me.CK_PI_Text.Text = CMain._T(tx.VALUES)

        Me.LB_MB_Dist.Text = CMain._T(tx.SPAN)
        Me.LB_PB_Dist.Text = CMain._T(tx.SPAN)
        Me.LB_MI_Dist.Text = CMain._T(tx.SPAN)
        Me.LB_PI_Dist.Text = CMain._T(tx.SPAN)

        Me.LB_MB_MarkSz.Text = CMain._T(tx.HLINE)
        Me.LB_PB_MarkSz.Text = CMain._T(tx.HLINE)
        Me.LB_MI_MarkSz.Text = CMain._T(tx.HLINE)
        Me.LB_PI_MarkSz.Text = CMain._T(tx.HLINE)

        Me.LB_MB_TextSz.Text = CMain._T(tx.HTEXT)
        Me.LB_PB_TextSz.Text = CMain._T(tx.HTEXT)
        Me.LB_MI_TextSz.Text = CMain._T(tx.HTEXT)
        Me.LB_PI_TextSz.Text = CMain._T(tx.HTEXT)

        Me.LB_M_MaxElCnt.Text = CMain._T(tx.MAXGRIDOBJ)
        Me.LB_P_MaxElCnt.Text = CMain._T(tx.MAXGRIDOBJ)


        '// VALUES  
        Me.CK_MB_Marker.Checked = CM_Grid.Stgs.M.BR_mrk
        Me.CK_PB_Marker.Checked = CM_Grid.Stgs.P.BR_mrk
        Me.CK_MI_Marker.Checked = CM_Grid.Stgs.M.IN_mrk
        Me.CK_PI_Marker.Checked = CM_Grid.Stgs.P.IN_mrk

        Me.CK_MB_Text.Checked = CM_Grid.Stgs.M.BR_txt
        Me.CK_PB_Text.Checked = CM_Grid.Stgs.P.BR_txt
        Me.CK_MI_Text.Checked = CM_Grid.Stgs.M.IN_txt
        Me.CK_PI_Text.Checked = CM_Grid.Stgs.P.IN_txt

        Me.TX_MB_Dist.Text = CM_Grid.Stgs.M.BR_dst.ToString()
        Me.TX_PB_Dist.Text = CM_Grid.Stgs.P.BR_dst.ToString()
        Me.TX_MI_Dist.Text = CM_Grid.Stgs.M.IN_dst.ToString()
        Me.TX_PI_Dist.Text = CM_Grid.Stgs.P.IN_dst.ToString()

        Me.TX_MB_MarkSz.Text = CM_Grid.Stgs.M.BR_csz.ToString()
        Me.TX_PB_MarkSz.Text = CM_Grid.Stgs.P.BR_csz.ToString()
        Me.TX_MI_MarkSz.Text = CM_Grid.Stgs.M.IN_csz.ToString()
        Me.TX_PI_MarkSz.Text = CM_Grid.Stgs.P.IN_csz.ToString()

        Me.TX_MB_TextSz.Text = CM_Grid.Stgs.M.BR_txh.ToString()
        Me.TX_PB_TextSz.Text = CM_Grid.Stgs.P.BR_txh.ToString()
        Me.TX_MI_TextSz.Text = CM_Grid.Stgs.M.IN_txh.ToString()
        Me.TX_PI_TextSz.Text = CM_Grid.Stgs.P.IN_txh.ToString()

        Me.TX_M_MaxElCnt.Text = CM_Grid.Stgs.m.iMaxObj.ToString()
        Me.TX_p_MaxElCnt.Text = CM_Grid.Stgs.P.iMaxObj.ToString()

        Select Case iMode
            Case MODE_MODEL 
                Me.Cancel_Button.Text = CMain._T(TX.CLOSE)
                Me.OK_Button.Text = CMain._T(TX.PICK)
                TP_Paper.Hide
                TP_Paper.Dispose
            Case MODE_PAPER
                Me.Cancel_Button.Text = CMain._T(TX.CLOSE)
                Me.OK_Button.Text = CMain._T(TX.PICK)
                TP_Model.Hide
                TP_Model.Dispose
            Case Else
                Me.OK_Button.Text = CMain._T(TX.OK)
                Me.Cancel_Button.Text = CMain._T(TX.CANCEL)
        End Select

    End Sub
    '// ===================================================================== '

    '// --------------------------------------------------------------------- '
    '// Get Settings
    Private Function GetStgs (ByRef lcStgs As CRJSTG, ByVal bMdl As Boolean, _
            ByVal bPpr As Boolean) As Boolean

        Dim bRet As Boolean = False
        Try
            lcStgs.M.BR_mrk = Me.CK_MB_Marker.Checked
            lcStgs.M.IN_mrk = Me.CK_MI_Marker.Checked
            lcStgs.P.BR_mrk = Me.CK_PB_Marker.Checked
            lcStgs.P.IN_mrk = Me.CK_PI_Marker.Checked

            lcStgs.M.BR_txt = Me.CK_MB_Text.Checked
            lcStgs.M.IN_txt = Me.CK_MI_Text.Checked
            lcStgs.P.BR_txt = Me.CK_PB_Text.Checked
            lcStgs.P.IN_txt = Me.CK_PI_Text.Checked

            bRet = True
            If (bMdl) Then
                bRet = bRet And CMain.GetDbl(Me.TX_MB_Dist.Text, lcStgs.M.BR_dst)
                bRet = bRet And CMain.GetDbl(Me.TX_MI_Dist.Text, lcStgs.M.IN_dst)
                bRet = bRet And CMain.GetDbl(Me.TX_MB_MarkSz.Text, lcStgs.M.BR_csz)
                bRet = bRet And CMain.GetDbl(Me.TX_MI_MarkSz.Text, lcStgs.M.IN_csz)
                bRet = bRet And CMain.GetDbl(Me.TX_MB_TextSz.Text, lcStgs.M.BR_txh)
                bRet = bRet And CMain.GetDbl(Me.TX_MI_TextSz.Text, lcStgs.M.IN_txh)
                bRet = bRet And CMain.GetInt(Me.TX_M_MaxElCnt.Text, lcStgs.M.iMaxObj)
            End if
            If (bPpr) Then
                bRet = bRet And CMain.GetDbl(Me.TX_PB_Dist.Text, lcStgs.P.BR_dst)
                bRet = bRet And CMain.GetDbl(Me.TX_PI_Dist.Text, lcStgs.P.IN_dst)
                bRet = bRet And CMain.GetDbl(Me.TX_PB_MarkSz.Text, lcStgs.P.BR_csz)
                bRet = bRet And CMain.GetDbl(Me.TX_PI_MarkSz.Text, lcStgs.P.IN_csz)
                bRet = bRet And CMain.GetDbl(Me.TX_PB_TextSz.Text, lcStgs.P.BR_txh)
                bRet = bRet And CMain.GetDbl(Me.TX_PI_TextSz.Text, lcStgs.P.IN_txh)
                bRet = bRet And CMain.GetInt(Me.TX_p_MaxElCnt.Text, lcStgs.P.iMaxObj)
            End if
        Catch ex As Exception
        End Try
        Return bRet

    End Function
    '// ===================================================================== '



End Class
'//  CLASS    =============================================================== '
'//
'//
'//
'//
'//  FUNCTIONS    ----------------------------------------------------------- '

'//  FUNCTIONS    =========================================================== '
'//
'//
'//
'//
'// ------------------------------------------------------------------------- '
'// ========================================================================= '
